package com.econ.powercloud.ems.controller;

import com.econ.powercloud.common.base.facade.pojo.MsgResult;
import com.econ.powercloud.common.base.facade.pojo.PageResult;
import com.econ.powercloud.ems.pojo.ProductVO;
import com.econ.powercloud.ems.service.biz.ProductConfigureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author : zjf
 * @Description : 产品配置controller
 * @Date : 2022/5/27 8:53
 * @Modified by : zjf
 */
@Api(tags = "产品配置")
@RestController
@RequestMapping(value = "/api/v2/product/configure")
public class ProductConfigureController extends ApiBaseController {

    @Autowired
    private ProductConfigureService productConfigureService;

    @ApiOperation(value = "获取产品配置列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "search", value = "产品名称/productKey", required = false,dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pageNo", value = "页码", defaultValue = "1", dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "每页大小", defaultValue = "20", dataType = "int")
    })
    @GetMapping(value = "getList")
    public MsgResult<PageResult<List<ProductVO>>> getCompanyInfo(@RequestParam(value = "search",required = false)String search,
                                                                 @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                                                                 @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize){
        return successHandler(productConfigureService.getList(search,pageNo,pageSize));
    }

    @ApiOperation(value = "同步产品列表")
    @PostMapping(value = "syncProduct")
    public MsgResult<String> syncProduct(){
        productConfigureService.syncProductList();
        return successHandler("同步产品列表成功！");
    }

    @ApiOperation(value = "更新产品信息")
    @PutMapping(value = "updateProductList")
    public MsgResult<String> updateProductList(){
        productConfigureService.updateAllProduct();
        return successHandler("更新产品信息成功！");
    }

    @ApiOperation(value = "更新某个产品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "productKey", value = "产品编号", dataType = "String"),
    })
    @PutMapping(value = "updateProduct")
    public MsgResult<String> updateProduct(String productKey){
        productConfigureService.updateProductByProductKey(productKey);
        return successHandler("更新产品信息成功！");
    }
}
